package com.test.booksystem.model;

import lombok.Data;

@Data
// 我们期望这个类能够告诉前端用户是否登录
public class Result<T> {
    private String message; // 如果登录成功则返回成功
    private StatusCode code; // 业务码 1-登录成功  -1-登录失败
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(StatusCode.SUCCESS);
        result.setMessage("用户登录");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail() {
        Result<T> result = new Result<>();
        result.setCode(StatusCode.FAIL);
        result.setMessage("用户未登录");
        result.setData(null);
        return result;
    }
}
